<?php
//简单管理页面范例，在你的管理页面引用coresection/checkA.php就OK，当然，不要忘了添加注销登录的链接
include_once '../coresection/checkA.php';
?>

<? $system_part = $_REQUEST ['sys_part']; ?>

<?
if(isset($_REQUEST['sys_part']))
{
    $system_part = $_REQUEST ['sys_part'];
}

if(isset($_REQUEST['nowpageid']))
{
    $nowpageid = $_REQUEST['nowpageid'];
}

if(isset($_REQUEST['sortby']))
{
    $sortby = $_REQUEST['sortby'];
}

if(isset($_REQUEST['term_nid']))
{
    $term_nid = $_REQUEST['term_nid'];
}

?>

<?php 

include_once("language.php");//属性名字
?>

<?
include_once("../../config_controller.php");
$host = $_SERVER['HTTP_HOST']; //取得进入所输入的域名
$theme_folder = host_theme($host);

include_once '../../front/' . $theme_folder . '/connection.php';include_once '../coresection/check_session.php';;
?>

<?php include_once ("function.php");?>
<?php include "../../front/".$theme_folder."/config.php" ;?>

<?php include_once ("../coresection/site-function.php");?>
<?php include_once ("term-detail-function.php");?>

<?php 
update_exists('`'.$dbName.'`.`'.$table_Prefix."term`" , '`is_disabled`' , 2);//检查表是否有这个字段  如果没有自动生成
?>
<?php include_once("first_term.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php include_once('../modules/head.php'); ?>

    <link href="../css/<?echo $theme_folder?>/user.css" rel="stylesheet" type="text/css"/>


<script type="text/jscript" src="../js/js.js" ></script>

	<?//js日期控件?>
<script src="/application/laydate/laydate.js"></script>
	


<!--kindeditor编辑器-->
<link rel="stylesheet" href="../keditor/themes/default/default.css" />
<script charset="utf-8" src="../keditor/kindeditor-all.js"></script>
<script charset="utf-8" src="../keditor/lang/zh_CN.js"></script>
<script>
			var editor;
			KindEditor.ready(function(K) {
				editor = K.create('textarea[name="term_detail"]', {
					allowFileManager : true
				});
 
			});
		</script>
<!--kindeditor编辑器-->
<script type="text/jscript" src="../js/jquery-1.10.2.min.js" ></script>
<script type="text/jscript" src="../js/drop.js" ></script>
<script type="text/jscript" src="../js/drop_title.js" ></script>

    <style>
        .layui-input-block {
            margin-left: 130px;
        }

        .layui-form-label {

            width: 100px;
        }


    </style>
</head>

<body>

<div id="topbar">
<!--TopBar端點01-->
<?php include '../modules/topbar.php'; ?>
<!--TopBar端點02-->
</div>

<div id="container">
<!--Container端點01-->
<div id="maincontent">
<!--maincontent端點01-->

<div id="sidebar">
<?php include '../modules/sidebar.php'; ?>
</div>
<style>
			.info{
				width: 100%;
			}
		</style>
        



<div id="content">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend><h1>编辑<? echo $sys_title ?> 分类</h1></legend>
    </fieldset>


<div class="detail-box <? echo $system_part ?>">


        
<div class="term-detail-boxes layui-form">
<ul class="detail-boxing">
<form id="term_detail_form" method="post" onsubmit="return checkRequired(term_name);"  action="term-edit-function.php" enctype="multipart/form-data" name="uploadfile" class="  layui-form-pane">

            <input name="term_nid" type="hidden" value="<?php echo $term_nid?>" />
            <li class="mid"><label class="layui-form-label">人工编号：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_mid" size="20" value="<?php echo $term_mid?>"></div>
                <em class="explain">(填写您自己设置的编号，人工编号不作排序)</em></li>
             
            <li class="name">
                <label class="layui-form-label">分类名称：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_name" size="20" value="<?php echo $term_name?>"></div>
                <em class="explain">(<u style="color:red">*必填项目</u>,填写本分类的标题)</em>
            </li>
            
            <li class="en_name">
                 <label class="layui-form-label">英文分类名称：</label>
                 <div class="layui-input-block"><input type="text" class="layui-input" name="term_en_name" size="20" value="<?php echo $term_en_name?>"></div>
                 
            </li>
            
            <li class="search_name">
                <label class="layui-form-label">关键字：</label>
    			<div class="layui-input-block"><input type="text" class="layui-input"  name="term_search_name" size="20" value="<?php echo $term_search_name?>"></div>
                <em class="explain">(填写多个关键字请用英文逗号区分好   例子 关键1,关键2)</em>
           </li>
                            
            <li class="term"><label class="layui-form-label">所属分类：</label>
            
     
            <? 
			if($term_interm=='term1'){$now_term=$term_term1;}
			else{$now_term=$term_term2;}
			
			
			?>
            
            <div class="layui-input-block">
            
           
            
            <select name="term_term_id" >
            
            
            <? if($term_interm=='root'){ ?> 
                <option value="root"  <? if($term_interm=='root'){ echo "selected='selected'";} ?> >
                    根目录
                </option>
             <? ;} ?>
                
                
              
                
                <?
                $table_Suffix = $sys_term_table;
                $table = $table_Prefix . $table_Suffix;
                $sort_by = "nid";
                $sort_order = "desc";
                ?>

                <?php
                $query = mysql_query("SELECT COUNT(nid) FROM $table where interm = 'root' and belong ='$sys_belong'");
                $term0sum = mysql_result($query, 0);

                $result_term0 = mysql_query("select * from $table where interm='root' and belong = '$sys_belong' ORDER BY $sort_by $sort_order");

                while($row = mysql_fetch_array($result_term0))
                {
                    $term0_nid[]=$row['nid'];
                    $term0_name[]=$row['name'];
                }

                ?>
                
                <? for($i=0;$i<$term0sum;$i++) { ?>
                
                 <? if($term_interm=='term1'){ ?> 
                    <option value="<?php echo $term0_nid[$i] ?>"  <? if($now_term==$term0_nid[$i]){ echo "selected='selected'";} ?>  > | - <?php echo $term0_name[$i] ?></option>
                
				<? ;} ?>
					
                    
                    
					
					<?
                    $query2 = mysql_query("SELECT COUNT(nid) FROM $table where term1 = $term0_nid[$i] && interm = 'term1'  and belong ='$sys_belong'  ");
                    $term1sum = mysql_result($query2, 0);
                    if ($_REQUEST ['sortby']) {
                        $sort_by = $_REQUEST ['sortby'];
                    }
                    $result1 = mysql_query("select * from $table where term1 = $term0_nid[$i] && interm = 'term1' and belong ='$sys_belong'  ORDER BY $sort_by ");
                    while ($row = mysql_fetch_array($result1)) {
                        {
                            $term1_nid[$i][] = $row['nid'];
                            $term1_mid[$i][] = $row['mid'];
                            $term1_name[$i][] = $row['name'];
                        }
                    }
                    ?>
                    
                    
            
                    <? if($term_interm=='term2'){ ?> 
                    
                    <? for ($ii = 0; $ii < $term1sum; $ii++) {?>
                        <option value="<?php echo $term1_nid[$i][$ii] ?>"   <? if($now_term==$term1_nid[$i]){ echo "selected='selected'";} ?>> |---- <?php echo $term1_name[$i][$ii] ?></option><? ;} ?>
                        
                         
                    <?php } ?>
                <?php } ?>

            </select></div>
                <em class="explain">(修改分类只支持同级移动，如是一级分类则不能修改)</em></li>
            
            
            
            <li class="introduce"><label class="layui-form-label">分类简介：</label>
              <div class="layui-input-block"><textarea name="term_introduce" cols="20"><? echo $term_introduce ?></textarea></div>
                <em class="explain">(填写本分类的分类概述文字)</em>
            </li>
            
            <li class="icon"><label class="layui-form-label">ICON图片：</label><img src="../../uploadfiles/<?echo $theme_folder?>/<? echo $term_icon ?>" width="100"/> <a href="term-delete-img.php?nid=<?php echo $trans_nid ?>&&img=icon"> 删除</a><span class="title-data">(请上传像素<? echo $first_icon_data[0]?>X<? echo $first_icon_data[1]?>的图片,格式为jpeg)</span></li>
            <li class="icon"><label class="layui-form-label">上传文件：</label>
    <div class="layui-input-block"><input type="file" name="icon"  onchange="fileChange(this);"/></div>
                <em class="explain">(上传本分类的列表图标)</em></li>
            
            <li class="banner"><label class="layui-form-label">横幅图片：</label><img src="../../uploadfiles/<?echo $theme_folder?>/<? echo $term_term_banner ?>" width="100"/> <a href="term-delete-img.php?nid=<?php echo $trans_nid ?>&&img=banner"> 删除</a><span class="title-data">(请上传像素<? echo $first_banner_data[0]?>X<? echo $first_banner_data[1]?>的图片,格式为jpeg)</span></li>
            <li class="banner"><label class="layui-form-label">上传文件：</label>
    <div class="layui-input-block"><input type="file" name="banner"  onchange="fileChange(this);"/></div>
                <em class="explain">(上传本分类的横幅Banner图片)</em></li>
			
            <li class="banner"><label class="layui-form-label">横幅标题：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_banner_title" value="<?php echo $term_info['banner_title']?>"></div>
                <em class="explain">(填写横幅标题内容)</em></li>
                
            <li class="banner"><label class="layui-form-label">横幅链接：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_banner_url" value="<?php echo $term_info['banner_url']?>"></div>
                <em class="explain">(填写横幅链接内容)</em></li>
                
            <li class="extend_img"><label class="layui-form-label"><?php echo $$term_extend_name ? $$term_extend_name : '备用'?>图片：</label><img src="../../uploadfiles/<?echo $theme_folder?>/<? echo $term_term_extend_img ?>" width="100"/> <a href="term-delete-img.php?nid=<?php echo $trans_nid ?>&&img=extend_img"> 删除</a><span class="title-data">(请上传像素<? echo $first_extend_img_data[0]?>X<? echo $first_extend_img_data[1]?>的图片,格式为jpeg)</span></li>
            <li class="extend_img"><label class="layui-form-label">上传文件：</label>
    <div class="layui-input-block"><input type="file" name="extend_img"  onchange="fileChange(this);"/></div>
                <em class="explain">(上传本分类的<?php echo $$term_extend_name ? $$term_extend_name : '备用'?>图片)</em></li>


            <li class="title"><label class="layui-form-label">网页用标题：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_title" size="20" value="<? echo $term_title ?>"></div>
                <em class="explain">(填写浏览器标签页显示的本分类页名称)</em></li>
			<li class="description"><label class="layui-form-label">网页用描述：</label><div class="layui-input-block"><textarea name="term_description"><? echo $term_description ?></textarea></div>
                <em class="explain">(填写本分类页描述性文字，用于搜索引擎的搜索结果显示)</em></li>
            <li class="keyword"><label class="layui-form-label">网页用关键词：</label><div class="layui-input-block"><textarea name="term_keyword"><? echo $term_keyword ?></textarea></div>
                <em class="explain">(填写本分类页的关键词，利于搜索引擎抓取)</em></li>
            <li class="url"><label class="layui-form-label">网页地址：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_url" size="20" value="<? echo $term_url ?>"></div>
                <em class="explain">(填写本分类页前台网址，用于伪静态设置，利于搜索引擎抓取)</em></li>

            <br />
            
             
                         <li class="detail">
 <label class="layui-form-label">分类详情：</label>
<div class="layui-input-block"><textarea name="term_detail" style="width:800px;height:400px;visibility:hidden;"><? echo $term_detail ?>
</textarea></div>
                <em class="explain">(填写本分类前台显示的详细文字介绍，默认留空)</em>
</li>


 

            <li class="listorder"><label class="layui-form-label">列表排序：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_listorder" size="20" value="<? echo $term_listorder ?>" onkeydown="onlyNum();" onfocus="checkdefault(term_listorder)" onblur="checkempty(term_listorder)"></div>
                <em class="explain">(填写本分类在所属前台列表下的列表排序，数字越大，排序越靠前)</em></li>
        
         
            <li class="hotsale"><label class="layui-form-label">热销分类：</label>
         		
                <div class="layui-input-block">
                    <input name='term_hotsale' type='radio' value='1'  title="标记热销" <?if($term_hotsale == '1'){echo "checked='checked'";}?>/>
                    <input name='term_hotsale' type='radio' value='0'  title="取消热销" <?if($term_hotsale == '0'){echo "checked='checked'";}?>/>
                </div>
           
                <em class="explain">(可标记热销分类，将在前台添加热销分类标识或显示热销产品分类)</em>
             </li>
             

            
             <li class="recommend"><label class="layui-form-label">推荐状态：</label>
             	
                 <div class="layui-input-block">
                    <input name='term_recommend' type='radio' value='1'  title="推荐分类" <?if($term_recommend == '1'){echo "checked='checked'";}?>/>
                    <input name='term_recommend' type='radio' value='0'  title="取消推荐" <?if($term_recommend == '0'){echo "checked='checked'";}?>/>
                </div>
          
                <em class="explain">(可标记推荐分类，将在前台添加推荐分类标识或显示推荐产品分类)</em>
             </li>
             
             
             <li class="link"><label class="layui-form-label">链接地址：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_link" size="20" value="<? echo $term_link ?>"></div>
                <em class="explain">(填写用于前台直接跳转的文章链接，类似于转载文章，默认留空)</em></li>
             
             
               
            <li class="mark"><label class="layui-form-label">标记状态：</label>
            
            	<div class="layui-input-block">
                    <input name='term_mark' type='radio' value='1'  title="添加标记" <?if($term_mark == '1'){echo "checked='checked'";}?>/>
                    <input name='term_mark' type='radio' value='0'  title="取消标记" <?if($term_mark == '0'){echo "checked='checked'";}?>/>
                </div>
           
                <em class="explain">(选择添加标记，以上信息将在前台显示；选择取消标记，以上信息不在前台显示)</em>
             </li>




            <li class="vip"><label class="layui-form-label">权限设置：</label>
            	
                <div class="layui-input-block">
                    <input name='term_vip' type='radio' value='0'  title="游客可见" <?if($term_vip == '0'){echo "checked='checked'";}?>/>
                    <input name='term_vip' type='radio' value='1'  title="vip1可见" <?if($term_vip == '1'){echo "checked='checked'";}?>/>
                    <input name='term_vip' type='radio' value='2'  title="vip2可见" <?if($term_vip == '2'){echo "checked='checked'";}?>/>
                </div>
                
              
                <em class="explain">(设置会员可浏览的权限)</em>
            </li>
             
             
             
             
             <li class="markorder"><label class="layui-form-label">标记排序：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_markorder" size="20" value="<? echo $term_markorder ?>" onkeydown="onlyNum();" onfocus="checkdefault(term_markorder)" onblur="checkempty(term_markorder)"></div>
                <em class="explain">(填写分类在前台列表中的排序，数字越大，排序越靠前)</em></li>
  
            <li class="clickrate"><label class="layui-form-label">点击次数：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_clickrate" size="20" value="<? echo $term_clickrate ?>" onkeydown="onlyNum();" onfocus="checkdefault(term_clickrate)" onblur="checkempty(term_clickrate)"></div>
                <em class="explain">(显示此分类在前台被浏览点击的次数，亦可在由后台管理员自行设置数量)</em></li>
            
			
			<li class="modifytime"><label class="layui-form-label">修改时间：</label>
    <div class="layui-input-block"><input type="text" class="layui-input"  name="term_modifytime" size="20" value="<? echo date("Y-m-d H:i:s") ?>" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" class="laydate-icon" ></div>
                <em class="explain">(填写分类修改时间)</em></li>
 
             <li class="publish"><label class="layui-form-label">发布状态：</label>
             
             	<div class="layui-input-block">
                    <input name='term_publish' type='radio' value='1'  title="立即发布" <?if($term_publish == '1'){echo "checked='checked'";}?>/>
                    <input name='term_publish' type='radio' value='0'  title="暂未发布" <?if($term_publish == '0'){echo "checked='checked'";}?>/>
                </div>
           
                <em class="explain">(选择立即发布，以上信息才能在前台显示；选择暂未发布，只对以上信息进行保存，不在前台显示)</em>
    
             </li>
			 
          
          <li class="layui-form-item is_disabled">
            <label class="layui-form-label">禁止删除：</label>
    
            <div class="layui-input-block">
                    <input name='term_is_disabled' type='radio' value='1'  title="禁止删除" <?if($term_is_disabled == '1'){echo "checked='checked'";}?>/>
                    <input name='term_is_disabled' type='radio' value='0'  title="允许删除" <?if($term_is_disabled == '0'){echo "checked='checked'";}?>/>
                </div>
                <em class="explain">(如标记了禁止删除，列表页下面不能删除当前信息)</em>
    
         </li>

    <div class="more_link">

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;" id="content4">
            <legend>关联品牌</legend>
        </fieldset>
        <br/>


        <div style="position:relative;">
            <div id="test4" class="demo-transfer"></div>
            <div class="buttonDiv">
                <button type="button" class="layui-btn layui-btnUpDownmax upMaxBtn" onclick="moveUpMax('test4')">
                    <i class="layui-icon">&#xe619;</i>
                    <i class="layui-icon">&#xe619;</i>
                </button>
                <button type="button" class="layui-btn layui-btnUpDown upBtn" onclick="moveUp('test4')">
                    <i class="layui-icon">&#xe619;</i>
                </button>
                <button type="button" class="layui-btn layui-btnUpDown downBtn" onclick="moveDown('test4')">
                    <i class="layui-icon">&#xe61a;</i>
                </button>
                <button type="button" class="layui-btn layui-btnUpDownmax downMaxBtn" onclick="moveDownMax('test4')">
                    <i class="layui-icon">&#xe61a;</i>
                    <i class="layui-icon">&#xe61a;</i>
                </button>

            </div>
        </div>
    </div>


    <input name="term_interm" type="hidden" value="<? echo $term_interm ?>" />
             <input name="sys_part" type="hidden" value="<? echo $system_part ?>" />
             <input name="nowpageid" type="hidden" value="<? echo $_REQUEST['nowpageid'] ?>" />
             <input name="sortby" type="hidden" value="<? echo $_REQUEST['sortby'] ?>" />
             
             
        <div class="function">
        <input type="hidden" name="detail_attr" id="detail_attr" />
            <button class="layui-btn " lay-submit  type="button" lay-filter="formSub">立即提交</button>
            <input type="reset" class="layui-btn" value="重置"/>
        </div>
</form>
</ul>
</div>
</div>

<!--content端點01-->
</div>
<!--maincontent端點01-->
<br class="clearfloat" />
</div>
<!--container端點01-->
</div>


<?php include ROOT_PATH_ . "/controller/modules/footer.php"; ?>


<script type="text/javascript">
layui.use(['transfer', 'layer', 'util', 'form'], function(){
	  var $ = layui.$
	  ,transfer = layui.transfer
	  ,layer = layui.layer
	  ,util = layui.util
	  ,form = layui.form;
	   
	
	var data1 = <?php echo $json_brand_list;?>  //显示搜索框
	transfer.render({
			elem: '#test4'
			,data: data1
			,title: ['全选', '全选']
			,showSearch: true
			,height:300
			,width:600
			,id: 'detail_attr_list'
			,value: [<?php echo $detail_relation_list;?>]
	}) 
	
	<?php 
	
	if( $detail_relation_list_json){?>
	var select_json = <?php echo $detail_relation_list_json;?>
	
	 setRightPosition(select_json, '#test4');				
	<?php }?>
	
						
	  form.on('submit(formSub)', function(data){
		 
		/*  var getData = transfer.getData('detail_attr_list'); 
		  
		  json_data = JSON.stringify(getData); */
		 
		  var ul = $("#test4").find("ul").eq(1);
			var input = $(ul).find("input");
			var saveArr = [];
			for(var i = 0; i < input.length; i++) {
				var inJson = {};
				
				inJson["title"] = input[i].title;
				inJson["value"] = input[i].value;
				saveArr.push(inJson);
			}
			json_data= JSON.stringify(saveArr)
		
		  $('#detail_attr').val(json_data)
			
			window.editor.sync();
			
			$('.layui-form-pane').submit() 	
	  })
	  
	  
});

//上移
		function moveUp(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent(); 
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=0;i<index.length;i++){
				if(index.eq(i).index()!=0){
					 index.eq(i).prev().before(index.eq(i));
				}
			}   
					
		}
		
		//置顶
		function moveUpMax(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent(); 
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=index.length-1;i>=0;i--){
				do{
					index.eq(i).prev().before(index.eq(i));
				}while(index.eq(i).index()!=0)
			}       			
		}
		
		//下移
		function moveDown(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent(); 
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=index.length-1;i>=0;i--){
				if(index.eq(i).index()!=($("#"+dom+" ul li").length-1)){
					 index.eq(i).next().after(index.eq(i));
				}
			}       			
		}
		
		//置底
		function moveDownMax(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent(); 
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=0;i<index.length;i++){
				do{
					index.eq(i).next().after(index.eq(i));
				}while(index.eq(i).index()!=($("#"+dom+" ul").eq(1).find("li").length-1))
			}       			
		}
		
		//穿梭框加载时不会按照设定的顺序来，需要删除重载
		function setRightPosition(json,dom) {
			var index = $(dom+ " ul").eq(1); 
			
			var list = json;
			var str = "";
			
			if(list){
				for(var i = 0; i < list.length; i++) {
					var inObj = list[i];
				
					var tagName = inObj.title;
					var htmlStr = $(index).children().children("input[title='"+tagName+"']").parent().prop("outerHTML");
				
					str += htmlStr;
				}
			}
			$(dom+" ul").eq(1).empty();
			$(dom+" ul").eq(1).append(str);
			
		}
		

</script>
</body>
</html>
